package com.gxar.timeline.server.base.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 货币枚举
 */
@Getter
public enum CurrencyEnum {

    USD("$", "美元", "USD", "美元"),
    CNY("¥", "人民币", "CNY", "元"),
    ;

    /**
     * 货币符号
     */
    private final String sign;
    /**
     * 货币名称
     */
    private final String name;
    /**
     * 货币标志
     */
    private final String symbol;
    /**
     * 货币单位
     */
    private final String unit;

    CurrencyEnum(String sign, String name, String symbol, String unit) {
        this.sign = sign;
        this.name = name;
        this.symbol = symbol;
        this.unit = unit;
    }

    /**
     * 根据单位符号获取币种
     *
     * @param unit 单位
     * @return 币种
     */
    public static Optional<CurrencyEnum> getByUnit(String unit) {
        return Arrays.stream(CurrencyEnum.values()).filter(e -> e.getUnit().equals(unit)).findFirst();
    }

    /**
     * 根据symbol查询
     *
     * @param symbol symbol
     * @return 币种
     */
    public static Optional<CurrencyEnum> getBySymbol(String symbol) {
        return Arrays.stream(CurrencyEnum.values()).filter(e -> e.getSymbol().equals(symbol)).findFirst();
    }
}
